



const ajax = options => {
    // 解构
    const {
        type = 'get',
        dataType = 'json',
        path,
        success
    } = options;

    const xhr = new XMLHttpRequest();
    xhr.open(type, path, true);
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            let data = xhr.responseText;
            if (dataType.toLowerCase() === 'json') {
                data = JSON.parse(data);
            }
            success(data);
        }
    }
}

